package org.styx.demo.component;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;


/**
 * 雪花算法实现主键
 *
 * @author uranus
 * @date 2021/10/27
 */
@Component
public class JPAAuditorAware implements AuditorAware<String> {
    @Override
    public Optional<String> getCurrentAuditor() {
        Snowflake snowflake= IdUtil.getSnowflake();
        String id=snowflake.nextIdStr();
       return Optional.of(id);
    }
}
